package com.batyuta.sort;

import java.io.File;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: alexey
 * Date: 10/19/11
 * Time: 12:25 AM
 * To change this template use File | Settings | File Templates.
 */
public class MergeQueueItem implements Serializable {
    private File fileFirst;
    private File fileSecond;
    private Integer lineCount;
    private Integer dept;

    public MergeQueueItem(File fileFirst, File fileSecond, Integer lineCount, Integer dept) {
        this.fileFirst = fileFirst;
        this.fileSecond = fileSecond;
        this.lineCount = lineCount;
        this.dept = dept;
    }

    public File getFileFirst() {
        return fileFirst;
    }

    public void setFileFirst(File fileFirst) {
        this.fileFirst = fileFirst;
    }

    public File getFileSecond() {
        return fileSecond;
    }

    public void setFileSecond(File fileSecond) {
        this.fileSecond = fileSecond;
    }

    public File getFileOut() {
        return new File(fileFirst.getParentFile().getParent() + "/" + dept + "/" + fileFirst.getName());
    }

    public Integer getLineCount() {
        return lineCount;
    }

    public void setLineCount(Integer lineCount) {
        this.lineCount = lineCount;
    }

    public Integer getDept() {
        return dept;
    }

    public void setDept(Integer dept) {
        this.dept = dept;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("");
        sb.append("\nFileFirst: ").append(fileFirst.getPath()).append(";");
        sb.append("\nFileSecond: ").append(null != fileSecond?fileSecond.getPath(): null).append(";");
        sb.append("\nFileOut: ").append(null != getFileOut()?getFileOut().getPath(): null).append(";");
        sb.append("\nDept: ").append(dept).append(";");
        sb.append("\nLineCount: ").append(lineCount).append(";");
        return sb.toString();

    }

    public static MergeQueueItem createNewFromResult(MergeQueueItem result) {
        return new MergeQueueItem(result.getFileOut(), null, result.lineCount, result.dept + 1);
    }
}
